<template>
  <el-card class="form-card">
    <h2>新建活动</h2>
    <el-form :model="form" @submit.prevent="onCreate" label-width="80px">
      <el-form-item label="标题">
        <el-input v-model="form.title" required />
      </el-form-item>
      <el-form-item label="描述">
        <el-input v-model="form.description" type="textarea" required />
      </el-form-item>
      <el-form-item label="开始时间">
        <el-date-picker v-model="form.startTime" type="datetime" placeholder="选择日期时间" style="width:100%;" />
      </el-form-item>
      <el-form-item label="最大人数">
        <el-input-number v-model="form.maxParticipants" :min="1" />
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model="form.type" placeholder="请选择活动类型">
          <el-option label="讲座" value="LECTURE" />
          <el-option label="比赛" value="COMPETITION" />
          <el-option label="社团招新" value="CLUB_RECRUITMENT" />
        </el-select>
      </el-form-item>
      <el-form-item label="报名表单JSON">
        <el-input v-model="form.formSchema" type="textarea" :rows="4" placeholder='[{"label":"学号","prop":"studentId","type":"input","required":true}]' />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" native-type="submit">创建</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { eventApi } from '../api/event'

const form = ref({ title: '', description: '', startTime: '', maxParticipants: 10, type: 'LECTURE', formSchema: '' })

const onCreate = async () => {
  await eventApi.createEvent(form.value)
  alert('创建成功')
  window.location.href = '/events'
}
</script>
<style scoped>
.form-card {
  max-width: 400px;
  margin: 40px auto;
}
</style> 